package com.xp.code.view;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import net.sf.json.JSONArray;

import org.apache.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.xp.code.services.IExampleService;
import com.xp.code.util.XPCodeSession;
import com.xp.code.vo.ExampleVO;
import com.xp.code.vo.MenuVO;

/**
 * 
 * @author HAHA
 * 
 */
@Controller("exampleAction")
@Scope("prototype")
public class ExampleAction {

	private static Logger loger = Logger.getLogger(ExampleAction.class);

	private String id;
	private String name;
	private String jsonString;


	@Resource(name = "exampleService")
	private IExampleService exampleService;

	public IExampleService getExampleService() {
		return exampleService;
	}

	public void setExampleService(IExampleService exampleService) {
		this.exampleService = exampleService;
	}

	public String getJsonString() {
		return jsonString;
	}

	public void setJsonString(String jsonString) {
		this.jsonString = jsonString;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getInfo1() {
		List<Object[]> info = this.exampleService.getInfo();
		List<MenuVO> list = new ArrayList<MenuVO>();
		MenuVO menue = null;
		for (Object[] obj : info) {
			menue = new MenuVO();
			menue.setId(obj[0].toString());
			menue.setVarcode(obj[0].toString());
			menue.setVarname(obj[1].toString());
			menue.setVarlevel("1");
			menue.setVarurl("example/content4.jsp");
			list.add(menue);
		}
		JSONArray jsonArray = JSONArray.fromObject(list);
		setJsonString(jsonArray.toString());
		loger.debug("getinfo1   out");
		return "success";
	}

	public String getInfo2() {
		loger.debug("getinfo2   in");
		
	    List<Object[]> info = this.exampleService.getInfo();
		List<ExampleVO> list = new ArrayList<ExampleVO>();
		ExampleVO menue = null;
		for (Object[] obj : info) {
			menue = new ExampleVO();
			menue.setEmpno(obj[0].toString());
			menue.setEname(obj[1].toString());
			menue.setHiredate(new Date(obj[2].toString()));
			menue.setJob(obj[3].toString());
			menue.setSal(new Double(obj[4].toString()));
			list.add(menue);
		}
	    JSONArray jsonArray = JSONArray.fromObject(list);
		setJsonString(jsonArray.toString());
	    loger.debug("getinfo2   out");
		return "success";
	}
}
